package edu.nju.mutest.mutator;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.expr.BinaryExpr;
import com.github.javaparser.ast.expr.Expression;
import edu.nju.mutest.util.CollectorUtil;
import edu.nju.mutest.visitor.collector.BinaryExprCollector;

import java.util.List;

import static com.github.javaparser.ast.expr.BinaryExpr.Operator.*;

public class LogicalConnectorReplacementMutator extends AbstractMutator{

    private final List<BinaryExpr.Operator> integerOps = List.of(BINARY_OR, BINARY_AND, XOR);
    private final List<BinaryExpr.Operator> booleanOps = List.of(OR, AND);

    public LogicalConnectorReplacementMutator(CompilationUnit cu) {
        super(cu);
    }

    @Override
    public List<CompilationUnit> mutate() {
        if (this.mutPoints == null)
            mutPoints = CollectorUtil.collect(new BinaryExprCollector(), this.origCU);

        for (Expression mp : mutPoints) {
            BinaryExpr be = (BinaryExpr) mp;
            generateMutantsForBinaryExpr(be, integerOps);
            generateMutantsForBinaryExpr(be, booleanOps);
        }
        return mutants;
    }

}
